package com.yang.springcloud.controller;


import com.mysql.cj.xdevapi.Client;
import com.yang.springcloud.pojo.Dept;
import com.yang.springcloud.service.DeptService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;
import sun.rmi.runtime.Log;

import java.util.List;

@RestController
@RequestMapping("/dept")
public class DeptController {

    @Autowired
    private DeptService deptService;
    @Autowired
    private DiscoveryClient discoveryClient;

    @PostMapping("/add")
    public boolean addDept(Dept dept){
        return deptService.addDept(dept);
    }


    @GetMapping("/queryById/{id}")
    public Dept queryById(@PathVariable("id")Long id){
        return deptService.queryById(id);
    }

    @GetMapping("/queryList")
    public List<Dept> queryList(){
        return deptService.queryList();
    }

    @GetMapping("/discovery")
    public Object discovery(){
        List<String> services = discoveryClient.getServices();
        System.out.println("services==>" + services);

        List<ServiceInstance> instances = discoveryClient.getInstances("SPRINGCLOUD-PROVIDER-DEPT");
        System.out.println("instances==>" + instances);

        return this.discoveryClient;
    }

}
